package multithreading;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*java线程池的使用*/
public class ExecutorsDemo {
    public static void main(String[] args) {
        System.out.println("try"+Thread.currentThread().getName());
        ExecutorService es = Executors.newFixedThreadPool(10);
        final CountDownLatch countDownLatch = new CountDownLatch(2);
        es.submit(()->{
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("oneTaskOne"+Thread.currentThread().getName());
            countDownLatch.countDown();
        });
        es.submit(()->{
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("twoTask"+Thread.currentThread().getName());
            countDownLatch.countDown();
        });

        System.out.println("mainThreads"+Thread.currentThread().getName());
        es.shutdown();
    }
}
